#include <gtkmm.h>
#include <iostream>
class MyDialog : public Gtk::Dialog {
public:
    MyDialog(Gtk::Window& parent, const Glib::ustring& title) :
        Gtk::Dialog(title, parent, true) { // true 表示模态对话框
        // 设置对话框标题
        set_title(title);

        // 添加按钮
        add_button("_OK", Gtk::RESPONSE_OK);
        add_button("_Cancel", Gtk::RESPONSE_CANCEL);

        // 获取内容区域
        Gtk::Box* content_area = get_content_area();

        // 创建标签并添加到内容区域
        Gtk::Label* label = Gtk::manage(new Gtk::Label("This is a simple dialog."));
        content_area->pack_start(*label);

        // 显示所有小部件
        label->show();
    }

    virtual ~MyDialog() {}
};

class MyWindow : public Gtk::Window {
public:
    MyWindow() {
        set_title("GTK+ Dialog Example");
        set_default_size(400, 200);

        // 创建按钮并连接信号
        Gtk::Button* button = Gtk::manage(new Gtk::Button("Show Dialog"));
        button->signal_clicked().connect(sigc::mem_fun(*this, &MyWindow::on_button_clicked));
        add(*button);

        button->show();
    }

    virtual ~MyWindow() {}

protected:
    void on_button_clicked() {
        // 创建并运行对话框
        MyDialog dialog(*this, "Example Dialog");
        int result = dialog.run();

        // 根据用户响应处理
        switch (result) {
            case Gtk::RESPONSE_OK:
                std::cout << "OK button clicked" << std::endl;
                break;
            case Gtk::RESPONSE_CANCEL:
                std::cout << "Cancel button clicked" << std::endl;
                break;
            default:
                std::cout << "Dialog closed with response: " << result << std::endl;
                break;
        }
    }
};

int main(int argc, char *argv[]) {
    auto app = Gtk::Application::create(argc, argv, "com.example.GtkDialogExample");
    MyWindow window;
    return app->run(window);
}
